package org.budo.support.java.collection.wrapper;

import java.util.Map;

import org.budo.support.fastjson.Fastjson;
import org.budo.support.lang.util.MapUtil;
import org.budo.support.lang.util.ReflectUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Slf4j
public class NiceToStringMapWrapper extends MapWrapper {
    private static final long serialVersionUID = -9080826329560794873L;

    private static final Boolean HAS_FASTJSON = ReflectUtil.hasClass("com.alibaba.fastjson.serializer.ValueFilter");

    public NiceToStringMapWrapper(Map map) {
        super(map);
    }

    public String toString() {
        if (!HAS_FASTJSON) {
            return MapUtil.toString(this);
        }

        try {
            return Fastjson.toJSONString(this);
        } catch (Throwable e) {
            log.error("#24 e=" + e, e);

            return MapUtil.toString(this);
        }
    }
}